import 'package:mi_mang_flutter/config/configs.dart';
import 'package:mi_mang_flutter/model/daily_word_model.dart';
import 'package:mi_mang_flutter/model/public/entity_factory.dart';
import 'package:mi_mang_flutter/model/public/page_model.dart';
import 'package:mi_mang_flutter/network/client.dart';
import 'package:mi_mang_flutter/network/response_data.dart';

/// 收藏接口
class FavoriteWordsApi {
  /// 每日一句收藏
  static const String API_FAVORITE_WORDS_SAVE = "/api/favorite-words/save";

  /// 删除每日一句收藏
  static const String API_FAVORITE_WORDS_REMOVE = "/api/favorite-words/remove";

  /// 分页获取收藏
  static const String API_FAVORITE_WORDS_GETPAGE =
      "/api/favorite-words/get_page";

  /// 每日一句收藏
  /// [dailyWordsId] 每日一句id
  static Future<ResponseData> favoriteWordsSave(
    int dailyWordsId,
  ) {
    return client.post(
      API_FAVORITE_WORDS_SAVE,
      data: {
        "dailyWordsId": dailyWordsId,
      },
    );
  }

  /// 删除每日一句收藏
  /// [dailyWordsId] 每日一句id
  static Future<ResponseData> favoriteWordsRemove(
    int id,
  ) {
    return client.post(
      API_FAVORITE_WORDS_REMOVE,
      data: id,
    );
  }

  /// 分页获取每日一句
  /// [pageNum]
  /// [pageSize]
  static Future<ResponseData<PageModel<DailyWordModel>>> getPage({
    int pageNum = 1,
    int pageSize = Configs.NETWORK_PAGE_SIZE,
  }) async {
    var response = await client.get(
      API_FAVORITE_WORDS_GETPAGE,
      queryParameters: {
        "pageNum": pageNum,
        "pageSize": pageSize,
      },
    );
    return ResponseData<PageModel<DailyWordModel>>(
        code: response.code,
        msg: response.msg,
        data: EntityFactory.generatePageOBJ(response.data));
  }
}
